package com.Maykk.Demo01;

/**
 * @ClassName Demo07
 * @Description: TODO 常用方法练习
 * @Author: MaykkSTAR@163.com
 * @DATE: 2023/4/24
 */
public class Demo07 {

    public static void main(String[] args) {
        String str = "abcdefghijklmnopqrstuvwxyz";

        //public char charAt(int index)返回给定索引位置的对应的字符
        System.out.println(str.charAt(0));
        System.out.println("=============================================");

        //public String concat(String str)字符串连接
        System.out.println("Java".concat("SE"));
        System.out.println("=============================================");

        //public boolean equals(Object anObject)比较字符串是否相等 -- 略

        //public byte[] getBytes()返回字节数组
        byte[] bytes = "Linux".getBytes();
        System.out.println("以下输出 “Linux” 的byte码");
        for (byte i : bytes) {
            System.out.println(i);
        }
        System.out.println("=============================================");

        //public int indexOf(int ch)查找给定字符的所在位置
        System.out.println(str.indexOf("z"));

        System.out.println("=============================================");

        //public int length()返回字符串长度
        System.out.println(str.length());
        System.out.println("=============================================");

        //public String[] split(String regex)拆分
        String strXiaosi = "小肆,男,18,未婚";
        String[] StrArrTest = strXiaosi.split(",");
        for (String i : StrArrTest) {
            System.out.println(i);
        }
        System.out.println("=============================================");

        //public String substring(int beginIndex, int endIndex)截取
        String num = "1234567890";
        System.out.println(num.substring(3, 6));
        // substring 截取的位置为3到5，截取到第二个数的前一位
        System.out.println("=============================================");

        //public char[] toCharArray()返回字符数组
        char[] charArray = str.toCharArray();
        for (char c : charArray) {
            System.out.print(c + ", ");
        }
        System.out.println();
        System.out.println("=============================================");

        //public String trim()去掉两端多余的空格
        String trim = " XiaoSi ";
        System.out.println("**" + trim.trim() + "**");
        System.out.println("=============================================");

        //public boolean isEmpty()判断是否为空串
        String s = "";
        String s1 = "abc";
        if (s.isEmpty())
            System.out.println("s为空");
        else
            System.out.println("s不为空");
        if (s1.isEmpty())
            System.out.println("s1为空");
        else
            System.out.println("s1不为空");
    }
}
